<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div{
      width: 200px;
      height: 200px;
      border: 2px solid red;
    }
  </style>
</head>
<body>
  <!-- vue.js -->
  <button onclick="page1()">界面1</button>
  <button onclick="page2()">界面2</button>
  <div></div>
  <script>
    var box = document.querySelector('div')
    function page1(){
      location.href = '#1' 
    }
    function page2(){
      location.href = '#2' 

    }


    // 路由切换的核心函数
    window.onhashchange = function(){
      // 判断当前的路由

      console.log(location)
      //  if 路由==1  界面是什么
      if (location.hash == '#1'){
        box.innerHTML = '<h1>现在是界面1</h1>'
      }

      //  if 路由 == 2  界面是什么
      if (location.hash == '#2'){
        box.innerHTML = '<h1>现在是界面2</h1>'
      }
      
      
    }
  </script>
</body>
</html>